<template>
	<view>
		<view class="">这个页面还没做</view>
		<view class="time" v-if="minute && orderDetail.status == '1'">
			剩{{minute}}分{{second}}秒自动关闭
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderDetail: {},
				targetTime: null,
				minute: 0,
				second: 0
			}
		},
		onLoad(options) {
			this.getOrderDetail(options.id)
		},
		methods: {
			getOrderDetail(id) {
				uni.$http.get(`/api/order/${id}`).then(res => {
					this.orderDetail = res.data.result
					if (this.orderDetail.status == '1') {
						this.handleCountDown()
					}
				})
			},
			handleCountDown() {
				// 设置30分钟后自动关闭待付款订单
				let createTime = Date.parse(this.orderDetail.createdAt)
				this.targetTime = createTime + 30 * 60 * 1000
				setInterval(this.handleTime, 1000)
			},
			handleTime() {
				// 获取当前时间戳
				let currentTime = new Date() - 0
				let count = (this.targetTime - currentTime) / 1000
				this.minute = parseInt(count / 60 % 60)
				this.second = parseInt(count % 60)
			}
		}
	}
</script>

<style>

</style>